package br.com.sadim.hospital;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

import br.com.sadim.paciente.Paciente;
import br.com.sadim.paciente.PacienteRN;

@FacesConverter(forClass=Paciente.class)
public class PacienteConverter implements Converter {
	private PacienteRN pacienteRN = new PacienteRN();
	@Override
	public Object getAsObject(FacesContext context, UIComponent component, String string) {
		if(string == null || string.isEmpty()){
			return null;
		}
		return pacienteRN.getById(Integer.valueOf(string));
	}
 
	@Override
	public String getAsString(FacesContext context, UIComponent component, Object object) {
		Paciente paciente = (Paciente) object;
		if(paciente == null || paciente.getIdPaciente() == null){
			return null;
		}
		return String.valueOf(paciente.getIdPaciente());
	}
}